//
// Unihan Input Method
//
// Copyright © 2002-2007 Sun Wah Linux Ltd.
//
//
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; either version 2.1 of the
// License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
// USA
//
// $Id: candidates.h 757 2007-05-10 08:19:31Z roger $
//

#ifndef _CANDIDATES_H
#define _CANDIDATES_H

#define CF_PREEDIT_MAX_LEN 50
#define PREEDIT_LEN_MAX 50

typedef enum _PhraseAchor {
	PhraseNone = 0,
	PhraseStart,
	PhraseEnd
} PhraseAchor;

typedef struct _InputList {
	int num;
	char **stringList;
	struct _InputList *next;
	struct _InputList *prev;
} InputList;

typedef struct _Candidate {
	int lowIdx;
	int highIdx;
	int exactIdx;
	int numCands;
	int numExactCands;
} Candidate;

/* Search Node */
typedef struct _SNode {
	char preedit[PREEDIT_LEN_MAX];
	int preeditLen;
	//int depth;
	Candidate *candidates;
	int numCands;
} SNode;

typedef struct _Node {
	int lowIdx;
	SNode *sNode;
	int numSNode;
	int numTotalCands;
	int page;
	int luCurrCandOffset;
	int currCands;
	Frequence *freqList;
	int kicked;
	int editing;
	int punc;
	const char *puncString;
	int defaultCandLen;
	InputList *inputList;
	InputList *lastInputList;
	PhraseAchor achor;
	struct _Node *prev;
	struct _Node *next;
} Node;

void node_destroy(Node *node);
int node_stacked(Node *node,
		IMKeyEvent *kev,
		TableConfig *config,
		BaseTable *base_table,
		Adjuster *adjuster,
		PhraseTableList *phrase_table_list);

void node_pop(Node *node,
		TableConfig *config,
		BaseTable *base_table,
		Adjuster *adjuster,
		PhraseTableList *phrase_table_list);

int node_kick(Node *node, IMKeyEvent *kev, TableConfig *config);
int node_page_up(Node *node, TableConfig *config);
int node_page_down(Node *node, TableConfig *config);
int node_sel_up(Node *node, TableConfig *config);
int node_sel_down(Node *node, TableConfig *config);

const char *node_get_candidates(Node *node,
			int index,
			BaseTable *base_table,
			PhraseTableList *phrase_table_list);

const char *node_get_preedit(Node *node);
int node_preedit_len(Node *node);
const char *node_get_selected_candidates(Node *node,
			BaseTable *base_table,
			PhraseTableList *phrase_table_list);
const char *node_get_default_cand(Node *node);
int snode_phrase_search(SNode *s_nodes,
			int num_s_node,
			BaseTable *base_table,
			PhraseTableList *phrase_table_list,
			int num_phrase_table);
void node_select_cand_from_snodes(Node *node,
			TableConfig *config,
			BaseTable *base_table,
			PhraseTableList *phrase_table_list,
			int num_phrase_table,
			SNode *s_nodes,
			int num_s_node,
			int index);
int node_is_last_in_phrase(Node *node,
			PhraseTableList *phrase_table_list,
			int num_phrase_table,
			SNode *s_nodes,
			int num_s_node);
void node_post_freq(Node *node,
		BaseTable *base_table,
		Adjuster *adjuster,
		TableConfig *config);

void node_set_first_cand(Node *node,
		int check_list_index,
		BaseTable *base_table,
		TableConfig *config);

#endif /* _CANDIDATES_H */

// vi:ts=4:nowrap:cin:expandtab
